home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16371 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: int (*p)[4]; (Watcom problem)
  5. Date: 10 Apr 1996 15:44:45 GMT
  6. Organization: Borland International
  7. Message-ID: <4kgl1d$6lm@druid.borland.com>
  8. References: <4kcd03$37j@morgoth.sfu.ca>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. Keywords: WATCOM C++ POINTER ARRAY PROBLEM
  13. X-Newsreader: WinVN 0.99.5
  14.  
  15. In article <4kcd03$37j@morgoth.sfu.ca>, mpohores@news.sfu.ca says...
  16. >
  17. >I came across (ARM, page 97) the following way to define
  18. >a pointer to an array:
  19. >   int (*p)[];
  20. >
  21. >(Yes, I allready know I can just do: int *p)
  22. >So I tried it in a small C++ test program: p2a.cpp
  23. >
  24. >#include <stdio.h>
  25. >
  26. >void main( void )
  27. >{
  28. >  int a[4] = { -13, 11, -7, 5 };
  29. >  int (*x)[4]; // pointer to array
  30. >
  31. >  for (int i = 0; i < 4; i++ )
  32. >  {
  33. >    (int *)x = &a[i];
  34. >    printf( "%d\n", (*x)[0] );
  35. >  }
  36. >}
  37. >
  38. >Now here's my problem:
  39. > Under Watcom 10.5, the above doesn't compile with wcl386
  40. >but it compiles under DJGPP 2.0, and Borland C++ 3.1  Anyone know why?
  41. >
  42. > Is this a bug?
  43.  
  44. Yes, your code has a serious bug. When you couldn't fit a round peg into a 
  45. square hole you used a hammer to make it fit. Get rid of the (int *) cast in 
  46. your assignment statement. Take the time to understand why it does not compile 
  47. and fix the problem. Hint: a pointer to an int is not the same thing as a 
  48. pointer to an array of ints.
  49.  
  50.